home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
system
/
fortn411.zip
/
FORTUNE.DOC
< prev
next >
Wrap
Text File
|
1994-11-07
|
21KB
|
473 lines
FORTUNE.DOC
11/07/94
The FORTUNE.EXE program adds some tuning features to the DOS FOR command (FOR
tune, fortune, what the heck). These features can in some way be applied to
commands accepting regular DOS wildcards. Features include:
* Results of command are written to a batch file which you can review before
you run it. Lets you subsequently edit it if desired and lets you see
exactly what commands will happen when you run it.
* Ability to embed redirection indicators in a command (see next example).
* Ability to separate the file name and file extension. For example:
FORTUNE IN (*.TXT) DO SORT %[ %A %] %1*.SOR
* Ability to identify individual characters in the the file name and extension.
For example:
FORTUNE IN (*.TXT) DO RENAME %A (%1%2%3%4%5%6).*
* Ability to specify a character other than "%" for the delimiter so you can
avoid worrying about different syntax in batch command vs command line
* Ability to have batch file pause after each command so results can be
reviewed.
* Ability to specify incrementation in the file names. For example:
FORTUNE IN (*.TXT) /+2 DO COPY %A %1*.%0001
* Ability to specify multiple statements on one command line.
* Ability to process children subdirectories (/S option) at same time. For
example:
FORTUNE IN (\*.TXT) /S DO COPY %A D:\BACKUPS
FORTUNE *.BAT /S DEL %A
* Ability to exclude up to 10 file specifications from consideration.
* Ability to do those tough PKZIP commands that you always wanted to do. Like
compress all *.FLI files in your subdirectory to a ZIP of the same name as
the original file:
FORTUNE *.FLI /DO PKZIP -M %R %e
* In addition, you can use the command to create a file which contains a
series of commands including a header and footer section which can be used
for some batch functions.
The DOS FOR command:
Quite a few DOS users are unaware of the DOS FOR command. It allows you to do a
single command over a series of files and provides an easy way to use wildcards
with commands that don't accept them. For example, if you want to type a number
of files to your screen, you can say something like:
FOR %A IN (*.TXT) DO TYPE %A
DOS looks at your IN specification and figures out what file names are covered
by that request. The request can include path information if desired and can
have multiple specification (e.g. "...IN (*.TXT \BAT\*.DOC)...").
FOR then substitutes the file name itself in for whatever variable you specify
in the first parameter after "FOR" ("%A" here). This variable is a single
character (A to Z) preceded by a single percent sign (%). (If FOR is used in a
batch command, you have to use two percent signs (%%) instead.)
FOR then looks at the command following the keyword "DO" and executes that
command. If it finds the variable name in the command, it substitutes the name
of the file for that variable.
So, in the above example, if you had three *.TXT files--ABLE.TXT, BAKER.TXT,
and CHARLIE.TXT--and you ran the command, it would actually do three commands
for you:
TYPE ABLE.TXT
TYPE BAKER.TXT
TYPE CHARLIE.TXT
All in all, FOR is a *very* useful command. There are also some DOS tricks that
you can use to make the command even more useful but, frankly, I always forget
the tricks. (If someone would like to e-mail them to me, I'll throw them in
here.) In any case, even past the tricks, the FORTUNE command provides even more
features.
FORTUNE wildcards and special characters:
The FORTUNE.EXE program extends the functionality of the DOS FOR command by
providing ways of splitting up the parts of the file name and manipulating the
parts. For example, someone in my office had a mess of files that had to be
renamed as an open parenthesis, followed by the first six characters of the file
name, followed by a close parenthesis. Not too terrible to handle with my text
editor but it hadn't occurred to her. Using FORTUNE, however, it's pretty easy:
FORTUNE IN (*.TXT) DO RENAME %A (%1%2%3%4%5%6).*
And then you run the newly-created batch file (DOIT.BAT).
Similarly, someone wanted me to rename a mess of files so they had sequential
names. I had to write a program to handle it. Definitely beyond his
capabilities. Again, using FORTUNE it's pretty easy:
FORTUNE IN *.TXT DO RENAME %A %1*.%0001
And again you run the DOIT.BAT file.
Within the command (DO command), FORTUNE allows you to include a number of
indicators. The character which indicates that it's a special character is
typically "%" but you can change this with the /VAR=char option in FORTUNE.
(You can also set the default by using the CONFIGWS program.) All of the
examples here use the default /VAR=% setting.
NOTE TO 4DOS USERS: 4DOS automatically translates %x characters even if used on
the command line. As such, 4DOS users *have* to use a different /VAR=x setting
to use FORTUNE. FORTUNE detects that you are running 4DOS and typically changes
the default /VAR=x to /VAR=@. This default can be changed by using the CONFIGWS
program.
In many cases, the indicators are case sensitive; there's a difference between
%p and %P. Typically, the lowercase variants are cumulative. %P gives you just
the path whereas %p throws in the drive information too.
%a translates into the entire file name (begins with drive,
colon, \, path, \, file root, ., file extension).
Use %R.%E if you want the filename without the drive/path info
%D translates into the drive (not followed by :)
%d translates into the drive (followed by :)
%P translates into path (not preceded or followed by \)
%p translates into path (begins with drive, colon, \, path, \)
%R translates into file name root
%r translates into file name root (begins with drive, colon, \,
path, \)
%E translates into file name extension
%e translates into file name extension (begins with drive, colon,
\, path, \, file name root, .)--same as %a
%1 to %8 characters 1 to 8 in the file name root
%X to %Z characters 1 to 3 in file name extension (case insignificant;
%X is the same as %x)
Standard DOS wildcards are supported within the file name. So %1* will give you
all characters in the file name root, %2* will give you all characters beginning
with the second character. "?" is also supported. Wildcards outside of the
special indicators work as expected ("...DO RENAME %A %1*.%X*" works
identically to "...DO RENAME %A *.*").
All other characters in the command string are passed as given.
Using the above characters, if you have two files C:\AUTOEXEC.BAT and
D:\WAYNE\MYSTUFF.TXT, the various codes above translate as:
C:\AUTOEXEC.BAT D:\WAYNE\MYSTUFF.TXT
%A C:\AUTOEXEC.BAT D:\WAYNE\MYSTUFF.TXT
%D C D
%d C: D:
%P (null) WAYNE
%p \ D:\WAYNE\
%R AUTOEXEC MYSTUFF
%r C:\AUTOEXEC D:\WAYNE\MYSTUFF
%E BAT TXT
%e C:\AUTOEXEC.BAT D:\WAYNE\MYSTUFF.TXT
%1 A M
%2 U Y
%3 T S
%4 O T
%5 E U
%6 X F
%7 E F
%8 C (null)
%X B T
%Y A X
%Z T T
Special translations:
%[ translates into <
%] translates into >
%0nnnn incrementer field (where "nnnn" is any number of digits;
translates into a numeric field which has the same number of
digits; the first number will be the value of "nnnn" and
subsequent files will be incremented by the value specified in
the /+n or /-n parameter (defaults to /+1)
Using a command file for special cases:
In addition, FORTUNE supports some options that might be used outside of a batch
file. (There are also several uses for this within a batch command but I won't
go into them here. Think about it on your own.) For example, let's say you have
an FTP program and you want to log onto the site and upload all of the *.TXT
files in your subdirectory. Normally, you'd do this by typing something like
this in response to the expected prompts:
ftp
ftp.cu.nih.gov (the name of the ftp site you're logging onto)
anonymous (your userid--I know, anonymous logins aren't
trusted for uploads; use your own userid)
bgu@cu.nih.gov (your password)
cd pub
cd incoming
Now, for each of the files you have, you'd have to enter a command like "send
filename", typically followed by a blank line when prompted for the recipient
file name.
Finally, after you're all done, you'd typically issue a "quit" command.
Thinking about it, you can use redirection in DOS to say "FTP < filename",
as long as the lines in the text file "filename" contain all of the statements
in sequence that you need to issue.
FORTUNE lets you specify a command file which contains a "header" section
(commands to be sent beforehand), a "main" section (commands to be sent for each
filename), and a "footer" section (commands to be send afterward). Each section
is optional and may consist of up to 20 commands. In our example, your command
file (we'll call it "FORTUNE.FTP" in this case) might look like this:
/header
ftp
ftp.cu.nih.gov
anonymous
bgu@cu.nih.gov
cd pub
cd incoming
/main
send %A
(blank line)
/footer
quit
The commands within the "main" section are repeated for each file and can
contain all of the standard FORTUNE features for the command section.
The sections can appear in any order.
To bring in the command file, specify "/DO @filename" instead of "/DO cmd".
So, your command line might be:
FORTUNE IN (*.TXT) DO @FORTUNE.FTP
This will create a DOIT.BAT file which, in fact, does not contain batch command
statements at all. If this bothers you, specify a different output file name if
you want. Then, to process this file in your FTP command, use standard
redirection:
FTP < DOIT.BAT
Note that using the command file feature disables processing of the FORTUNE
parameters which are specific to batch files. These ignore parameters are:
/ECHO, /-ECHO, /ABEND, /-ABEND, /PAUSE, and /-PAUSE.
In addition, you can specify a file that contains the filenames to process by
using "/IN @filename". This feature can be very handy when /-CHECK is specified
and the file itself contains file names on a remote host. For example, this is
useful if you're trying to run something like FORTUNE on an ftp host over the
Internet to issue a series of "get" commands on that host.
One disadvantage of the /-CHECK parameter is that it will not parse out the file
name at all so only %A-like requests will do any good.
The FORTUNE.INI file:
FORTUNE will read a FORTUNE.INI file if one is found. (You can specify a
different file name if desired.) The file is an ASCII text file that can be
created maintained by hand. The file can consist or one or more command line
parameters (only those that begin with a "/"), one statement per line.
The file can also contain comments which are blank lines or any line beginning
with:
; (semi-colon)
: (colon)
' (quote)
FORTUNE looks for the initialization file in your default subdirectory first.
It then searches for it in the subdirectory where the executable was and then
goes through your DOS path.
Passing in "/-I" or "/INULL" skips loading the FORTUNE.INI file.
CONFIGWS.EXE:
In addition to using the FORTUNE.INI file, you can permanently change some
defaults within FORTUNE.EXE by using the CONFIGWS.EXE program. CONFIGWS.EXE is
not included in the FORTUNE distribution package but previous versions can
typically be used with FORTUNE if desired. (The same CONFIGWS.EXE program can
be used to path a number of Wayne Software programs.) If CONFIGWS can't patch
the executable, it will notify you of this before altering anything.
CONFIGWS.EXE allows you to set the following defaults:
Variable char: /VAR=char
Abort on error: /ABORT or /-ABORT
Echo commands: /ECHO or /-ECHO
Pause between: /PAUSE or /-PAUSE
When setting options, the program will process defaults in the following order:
(1) CONFIGWS.EXE-settable settings
(2) FORTUNE.INI settings
(3) command-line settings
The *last* settings encountered win.
Syntax:
FORTUNE { IN (set) | IN set | /IN (set) | /IN filespec | filespec }
[ /AS filename ] [ /OVERWRITE | /APPEND | /-OVERWRITE | /OVERASK ]
[ /VAR=char ] [ /DELIM=chars ] [ /+n | /-n ] [ /S ] [ /Xfilespec ] ...
[ /ECHO | /-ECHO ] [ /ABEND | /-ABEND ] [ /PAUSE | /-PAUSE ]
[ /CHECK | /-CHECK ] [ /Iinitfile | /-I ] [ /? ]
{ DO cmd | /DO cmd | cmd }
where:
"IN (set)" lets you specify the file names to be processed. Multiple file
specifications should be separated by a space or a semicolon. The "IN" can be
preceded by a "/" if desired. If only one file specification is provided, you
can skip the parentheses. You can specify "%PATH%" (depending on the value of
the /DELIM=chars option) if you want. A file specification is required for
FORTUNE.
You can specify an input file that contains the file list to process. This is
done using "@filename" instead of "set" or "filespec".
It's possible to leave off the "IN" (or its derivatives) as well as the
parentheses if your file specification(s) include a "/", "*", or "?" character.
For example:
FORTUNE *.BAS *.DOC DO TYPE %A
"/AS filename" tells the command the name of the batch file to create with the
resulting commands. By default, this file will be called DOIT.BAT and it will
be created in your default subdirectory.
"/OVERWRITE" says to write over any output file that's already there.
"/APPEND" says to add the new records at the end of any output file that's
already there. Note that FORTUNE uses several DOS labels every time it executes
and concatenation is typically not recommended.
"/-OVERWRITE" says to abort if the output file exists already.
"/OVERASK" says to prompt if the output file exists already; this is the
default.
"/VAR=char" indicates the character to use as the special character indicator.
This typically defaults to "/VAR=%" under DOS and "/VAR=@" under 4DOS. This
default can be changed using the CONFIGWS program. The hassle with this is that
if you invoke FORTUNE from a batch file, you'll have to remember to use %%
instead of %. If you pick another character (like /VAR=^), that's not
necessary.
"/DELIM=chars" allows you to indicate delimiters to use between statements
within the DO command. Defaults to "/DELIM=$$". This allows you to process
multiple statements in a single FORTUNE command. For example:
FORTUNE IN *.BAS DO COPY %A \TEMP $$ TYPE \TEMP\%R.%E
Note that the number of characters can be any length (including one character).
Your only consideration is that the characters do not appear together in
your command otherwise. The characters are case insignificant ("/DELIM=newline"
and "/DELIM=NEWLine" are the same thing).
"/+n" and "/-n" allow you to specify the increment/decrement value to be
used where %0nnnn indicators are used in the command line. Defaults to "/+1".
"/S" processes the children subdirectories as well. So you could do something
like any of the following:
FORTUNE IN (\*.BAS) /S COPY %A LPT1:
FORTUNE IN (\OLD*.TXT) /S DO DELETE %A
The next example is a little bizarre. Let's say you're using anti-virus
protection program that maintains a read-only file in each subdirectory with all
of the virus signatures for the files in that subdirectory. You decide you no
longer want to use that program again but you have a zillion of these files and
they're all read-only. The following example would search them all out, reset
them to not be read-only, and then delete them.
FORTUNE IN (\VIRCK.SIG) /S DO ATTRIB %A -R $$ DEL %a
"/Xfilespec" says to exclude certain filespecs from being considered. You can
specify up to 10 exclusion parameters but each must have their own /Xfilespec
statement. For example, you could process all *.BAS files except D*.BAS files
by saying "FORTUNE IN (*.BAS) /XD*.BAS DO TYPE %A".
"/ECHO" says to turn ECHO ON in the batch file. This will show the command
being executed before it executes. This is typically the default but this can
be changed using the CONFIGWS program.
"/-ECHO" says to turn ECHO OFF in the batch file.
"/ABEND" (abnormal end) says to use standard DOS errorlevel trapping to see if
there was an error in running the command. If any non-0 errorlevel condition is
encountered (e.g. an error has occurred), the batch file will branch out,
skipping the rest of the statements in the batch file and aborting. Note that
not all commands return decent errorlevel codes. COPY, for example, doesn't set
an errorlevel to indicate that the file could not be found. "/ABEND" is the
typically the default but you can change this using the CONFIGWS program.
"/-ABEND" says to skip errorlevel testing.
"/PAUSE" says to add a PAUSE statement after each statement that's executed.
If you don't like what you see, you can press Ctrl-Break and get out of the
batch file.
"/-PAUSE" skips the PAUSE statements. This is typically the default but you can
change this using the CONFIGWS program.
"/Iinitfile" says to read an initialization file with the file name "initfile".
The file specification *must* contain a period. If no drive or path information
is specified, the program will search for initfile beginning in your default
subdirectory and then going throughout your DOS path. The use of an
initialization file is optional. Initially defaults to "/IFORTUNE.INI".
"/-I" (or "/INULL") says to skip loading the initialization file.
"/?" or "/HELP" or "HELP" shows you the syntax for the command.
"DO cmd" (or "/DO cmd") specifies the command(s) to be executed. A slash before
"DO" is optional. A DO (or /DO) command is required. Multiple commands can be
specified if they are separated using the characters specified in the
/DELIM=chars parameter. You can also use a command file by using /DO @filename;
see the previous discussion on "Using a command file for special cases".
In most cases, the use of the "DO" (or "/DO") parameter is actually unnecessary.
The routine typically treats all of the following as identical:
FORTUNE IN (*.BAS *.DOC) /DO TYPE %A
FORTUNE IN (*.BAS *.DOC) TYPE %A
FORTUNE *.BAS *.DOC TYPE %A
However, using the "DO" (or "/DO") parameter adds an extra left of error
checking and its use it encouraged.
Return codes:
FORTUNE returns the following ERRORLEVEL codes:
0 = no problems, files found and batch file created
1 = no problems, no files met specifications
255 = syntax problems, file not found, or /? requested
Author:
This program was written by Bruce Guthrie of Wayne Software. It is free for use
and redistribution provided relevant documentation is kept with the program, no
changes are made to the program or documentation, and it is not bundled with
commercial programs or charged for separately. People who need to bundle it in
for-sale packages must pay a $50 registration fee to "Wayne Software" at the
following address.
Additional information about this and other Wayne Software programs can be found
in the file BRUCEymm.DOC which should be included in the original ZIP file.
("ymm" is replaced by the last digit of the year and the two digit month of the
release. BRUCE312.DOC came out in December 1993. This same naming convention
is used in naming the ZIP file that this program was included in.) Comments and
suggestions can also be sent to:
Bruce Guthrie
Wayne Software
113 Sheffield St.
Silver Spring, MD 20910
fax: (301) 588-8986
See BRUCEymm.DOC file for additional contact information.
Foreign users: Please provide an Internet e-mail address in all correspondence.